package pattern.structrual.event;

/**
 * @Author Gavin
 * @date 2021.03.05 15:16
 */
public class Test {
    public static void main(String[] args) throws InterruptedException {
        EventSource eventSource=new EventSource();
        eventSource.addListener(event -> {
            if(event.name.equals("A")){
                System.out.println("A事件监听到了");
            }
        });
        eventSource.addListener(event -> {
            if(event.name.equals("A")){
                System.out.println("第二个监听器也监听到了A事件");
            }
        });
        eventSource.addListener(event -> {
            if (event.name.equals("B")){
                System.out.println("B事件监听到了。");
            }
        });
        Event A=new Event("A");
        Event B=new Event("B");
        eventSource.notifyEvent(A);
        Thread.sleep(1000);
        eventSource.notifyEvent(B);
    }
}
